package com.cy.store.service.impl;

import com.cy.store.entity.District;
import com.cy.store.mapper.DistrictMapper;
import com.cy.store.service.IDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DistrictServiceImpl implements IDistrictService {
    @Autowired(required = false)
    private DistrictMapper districtMapper;

    /**
     * 根据parent查询
     *
     * @param parent
     * @return
     */
    @Override
    public List<District> getByParent(String parent) {
        List<District> list = districtMapper.findByParent(parent);
        /**
         * 在进行网络数据传输的时候，为了尽量避免无效数据的传送，可以将无效数据设置为null
         * 节省流量，提升效率
         */
        for (District district : list) {
            district.setId(null);
            district.setParent(null);
        }

        return list;
    }

    /**
     * 根据code查询区域name
     * @param code
     * @return
     */
    @Override
    public String getNameByCode(String code) {
        return districtMapper.findNameByCode(code);
    }
}
